-- Arena
-- Created by chengb Dec/14/2015
-- 角斗台格子

-- 初始化
function initArena(self)
    self.item:removeAllChildren();

    local unrealId = self.gridData.unrealId;
    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 获取格子位置
            local pos = self.gridData:getPos();

            -- 音效
            AudioM.playFx("workshop_store");

            local desc = UnrealDungeonM.query(unrealId, "desc");

            -- 判断是否逃离过
            local isLeave = ArenaM.hasEverFlee(DungeonM.currentLayer());
            if isLeave then
                desc = desc .. getLocStr("arena_enter_tip2");
            else
                -- 获取与玩家角斗的冈布奥名称
                local classId = ArenaM.getCombatSlimeId();
                local name = MonsterM.query(classId, "name");
                desc = desc .. string.format(getLocStr("arena_enter_tip1"), name);
            end

            -- 打开夹层进入界面
            UIMgr.getCurrentScene():removeFormByName("UIUnrealEnter");
            local uiUnrealEnter = UIUnrealEnter.create(pos, unrealId, desc, isLeave);
            UIMgr.getCurrentScene():addForm(uiUnrealEnter);
        end
    end

    local iconIndex = UnrealDungeonM.query(unrealId, "icon");
    local iconPath = getLevelItemIconPath(iconIndex);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
